//
//  ApiClient.m
//  weappios
//
//  Created by chensentao on 2018/8/3.
//  Copyright © 2018年 XiGuangLu. All rights reserved.
//

#import "AppContext.h"
#import "SaveHelper.h"

@interface AppContext()

@end

@implementation AppContext

+(AppContext*)sharedContext
{
    static dispatch_once_t token;
    static AppContext* api;
    dispatch_once(&token, ^{
        api=[[AppContext alloc] init];
    });
    return api;
}

-(instancetype)init
{
    self = [super init]; //用于初始化父类
    if (self) {
      //初始化
        _curChannel=[SaveHelper getSaveStr:@"channel"];
        _curUid=[SaveHelper getSaveStr:@"curUid"];
        _clientId=[SaveHelper getSaveStr:@"cid"];
        _loadtag=[SaveHelper getSaveStr:@"tag"];
        _versionCode=[SaveHelper getSaveStr:@"version"];
        _userAgent=[SaveHelper getSaveStr:@"userAgent"];
        _udid=[SaveHelper getSaveStr:@"udid"];
        _uid=[SaveHelper getSaveStr:@"uid"];
        _isVip=[SaveHelper getSaveInt:@"isVip"];
        _accredit=[SaveHelper getSaveStr:@"accredit"];
    }
    return self;
}

-(void)setCurUid:(NSString *)curUid
{
    _curUid=curUid;
    [SaveHelper saveStr:@"curUid" vlu:_curUid];
}

-(void)setCurChannel:(NSString *)curChannel
{
    _curChannel=curChannel;
    [SaveHelper saveStr:@"channel" vlu:_curChannel];
}

- (void)setClientId:(NSString *)clientId {
    
    _clientId=clientId;
    [SaveHelper saveStr:@"cid" vlu:_clientId];
}

- (void)setLoadtag:(NSString *)loadtag {
    
    _loadtag=loadtag;
    [SaveHelper saveStr:@"tag" vlu:_loadtag];
}

- (void)setVersionCode:(NSString *)versionCode {
    
    _versionCode=versionCode;
    [SaveHelper saveStr:@"version" vlu:_versionCode];
}
    
- (void)setUserAgent:(NSString *)userAgent {
    
    _userAgent=userAgent;
    [SaveHelper saveStr:@"userAgent" vlu:_userAgent];
}

- (void)setUdid:(NSString *)udid {
    
    _udid=udid;
    [SaveHelper saveStr:@"udid" vlu:_udid];
}

- (void)setUid:(NSString *)uid {
    
    _uid=uid;
    [SaveHelper saveStr:@"uid" vlu:_uid];
}

- (void)setIsVip:(int)isVip {
    
    _isVip=isVip;
    [SaveHelper saveInt:@"isVip" vlu:_isVip];
}

- (void)setAccredit:(NSString *)accredit {
    
    _accredit=accredit;
    [SaveHelper saveStr:@"accredit" vlu:_accredit];
}

@end
